<template>
	<view>
		<view
			style="color: #00bf92;width: 90%;margin: 30rpx auto;box-shadow: 0 0 40rpx #00c297;padding: 20rpx;border-radius: 20rpx;">
			<uni-calendar :selected="selected" @change="change" />
		</view>
		<view style="width: 100%;">
			<view class="qiandaobtn" @click="signin">{{a==true?'点击签到':'已签到'}}</view>
			<view v-if="a" class="tishi">今日未签到</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				selected: [{
					date: '2022-07-02',
					info: '已签'
				}, {
					date: '2022-07-03',
					info: '已签'
				}],
				a:true,//判断是否已签到
			}
		},
		onLoad() {
			// 判断是否已签到
			let newtime = uni.$u.timeFormat(Number(new Date()), 'yyyy-mm-dd')
			let oldtime = (this.selected.reverse())[0].date
			if (newtime == oldtime) {
				this.a=false
			}
			console.log(newtime, oldtime);
		},
		methods: {
			change(e) {
				console.log(e);
			},
			signin() {
				if (this.a) {
					let newtime = uni.$u.timeFormat(Number(new Date()), 'yyyy-mm-dd')
					// 签到接口
					
					// 成功回调
					console.log(this.selected.push({
						date: newtime,
						info: '已签'
					}));
					this.a=false
				}
			}
		}
	}
</script>

<style>
	.qiandaobtn {
		width: 250rpx;
		height: 250rpx;
		background-color: #00c297;
		margin: 0 auto;
		margin-top: 10rpx;
		border-radius: 50%;
		line-height: 250rpx;
		text-align: center;
		color: #fff;
		box-shadow: 0 0 20rpx #909090;
	}

	.tishi {
		width: 300rpx;
		height: 80rpx;
		background-color: #ff5e81;
		margin: 0 auto;
		border-radius: 60rpx;
		line-height: 80rpx;
		text-align: center;
		box-shadow: 0 0 20rpx #909090;
		color: #fff;
		position: relative;
		top: -30rpx;
	}
</style>
